<% if request.xhr? %>
<div class="c-right fl">
	<a class='right' href="#" onclick="$.colorbox.close()">关闭</a>
<% end %>
	<div class="tblsitebox">
	        <h3 class="tblsitename">#<%=@task.id%> [<%=h @task.project ? @task.project.name : '无'%>] <%=@task.name%></h3>
		<h4></h4>
		<table cellpadding="0" cellspacing="0" width="100%" class="tblsite"> 
			<tbody class="tblsite-bd">
				<tr>
					<td><b>创建人</b></td>
					<td><%=@task.user ? @task.user.name : '无'%></td>

					<td><b>处理人</b></td>
					<td><%= @task.assign_to ? @task.assign_to.name : '-'%></td>

					<td><b>重要性</b></td>
					<td><%=@task.important ? '重要' : '普通'%></td>

					<td><b>紧迫性</b></td>
					<td><%=@task.urgent ? '紧急' : '一般'%></td>
				</tr>
				<tr>
					<td><b>项目</b></td>
					<td colspan=7><%=h @task.project ? @task.project.name : '无'%></td>
				</tr>
				<tr>
					<td><b>描述</b></td>
					<td colspan=7><%=h @task.description%></td>
				</tr>
				<tr>
					<td><b>状态</b></td>
					<td><%=@task.status%></td>

					<td><b>创建日期</b></td>
					<td><small><%=@task.created_at.strftime("%F %T")%></small></td>

					<td><b>期望日期</b></td>
					<td><small><%=@task.due.strftime("%F %T")%></small></td>

					<td><b>完成日期</b></td>
					<td><small><%=@task.finished? ? (@task.updated_at ? @task.updated_at : @task.finished_at).strftime('%F %T') : '-'%></small></td>
				</tr>
				<tr>
					<td><b>关注者</b></td>
					<td colspan=7>
					<%= @task.monitors.user.map{|m| m.name}.join(', ') %>
					</td>
				</tr>
			</tbody>
		</table>

	<% unless @task.finished? %>
		<form class='right' method="POST" action="<%=@task.link%>">
			<input name="_method" type="hidden" value="PUT" />
			<input type='submit' value='分配给'>
			<select name='assign_to'>
			<% @users.each do |user| %>
				<option value="<%=user.id%>" <%=(@task.assign_to and @task.assign_to.id == user.id) ? 'selected' : '' %>><%= user.name %></option>
			<% end %>
			</select>
		</form>

		<form class='right' method="POST" action="<%=@task.link%>">
			<input name="_method" type="hidden" value="PUT" />
			<input type='submit' value='更新状态为'>
			<select name='status'>
			<% @tasklet_next_status.each do |status| %>
				<option value="<%=status%>" <%=(@task.status == status) ? 'selected' : '' %>><%=status%></option>
			<% end %>
			</select>
		</form>

		<form class='right' method="POST" action="<%=@task.link%>">
			<input name="_method" type="hidden" value="PUT" />
			<input name="monitor_add" type="hidden" value=true />
			<input type='submit' value='添加'>
			<select name='user_id'>
			<% @users.each do |user| %>
				<option value="<%=user.id%>" <%=(@current_user.id == user.id) ? 'selected' : '' %>><%= user.name %></option>
			<% end %>
			</select>
		</form>


		<form class='right' method="POST" action="<%=@task.link%>">
			<input name="_method" type="hidden" value="PUT" />
			<input name="monitor_add" type="hidden" value=true />
			<input name="user_id" type="hidden" value="<%=@current_user.id%>" />
			<input type='submit' value='关注'>
			<!--
			<select name='user_id'>
			<% @users.each do |user| %>
				<option value="<%=user.id%>" <%=(@current_user.id == user.id) ? 'selected' : '' %>><%= user.name %></option>
			<% end %>
			</select>
			-->
		</form>

	<%else%>
		<form class='right' method="POST" action="<%=@task.link%>">
			<input name="_method" type="hidden" value="PUT" />
			<input name="status" type="hidden" value="reopen" />
			<input type='submit' value='重新打开'>
		</form>

	<%end%>
	</div>

	<div class="tblsitebox">
	        <h3 class="tblsitename">轨迹</h3>
		<table cellpadding="0" cellspacing="0" width="100%" class="tblsite"> 
			<tbody class="tblsite-bd">
			<% @traces.each do |trace|%>
				<tr>
					<td>
						<b><%=h trace.user.name %></b><br />
						<small><a href="#" title="<%=trace.check_point%> <%=trace.id%>"><%= trace.created_at.strftime("%F %T") %></a></small>
					</td>
					<td><b><%= trace.name %></b><br />
						<%=h trace.description %>
					</td>
					<td>
					<% if trace.check_point? %>
						期望日期<%= trace.due.strftime("%F %T") %><br />
						<% if trace.finished? %>
							<%= trace.overdue? ? '延期' : '' %>完成于<%= trace.finished_at.strftime("%F %T") %>
						<% else %>
							<%= trace.overdue? ? '已延期' : '进行中' %>
							<form  method="POST" action="<%=trace.link%>">
								<input name="_method" type="hidden" value="PUT" />
								<input name="finished" type="hidden" value=true />
								<input name="user_id" type="hidden" value=<%=@current_user.id%> />
								<input type='submit' value='done'>
							</form>
						<%end%>
					<% else %>
						-
					<% end %>
					
					</td>
				<tr>
			<% end %>
			</tbody>
		</table>


<% unless @task.finished? %>
		<form action="/trace/create" method="POST">
			<fieldset>
				<legend>新增轨迹</legend>
				<input type='text' name='name' size='48' />
				<input type='radio' name='check_point' value=1 id='form_trace_check_point'><label for='form_trace_check_point'>检查点</label>
				<input type='radio' name='check_point' value=0 id='trace_normal' checked><label for='trace_normal'>普通</label>
				<br />

				<textarea cols="72" rows="4" name='description'></textarea>
				<br />

				<label>期望日期</label>
				<input type="date" name="due" value='<%=(Time.now+86400).strftime("%F %T") %>' id='check_point_due' />
				<input type="hidden" name="user_id" value=<%=@current_user.id%> />
				<input type="hidden" name="tasklet_id" value=<%=@task.id%> />

				<input style="float: right;" type='submit' value='创建轨迹'>
<script>
$.ready(function() {
	$("input[name='check_point'] #form_trace_check_point").click(function(){
		$("input[name='due'] #check_point_due").attr('disabled') = true;
	});
	$("input[name='check_point'] #trace_normal").click(function(){
		$("input[name='due'] #check_point_due").attr('disabled') = false;
	});
});
</script>
			</fieldset>
		</form>
	</div>

<% end %>
<% if request.xhr? %>
</div>
<% end %>
